<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8" />
  <title>Hello World</title>
  <script src="https://unpkg.com/react@16/umd/react.development.js"></script>
  <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
  <script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
</head>

<body>
  <div id="root"></div>
  <script type="text/babel">

    class Reservation extends React.Component{
      constructor(props){
        super(props);
        this.state = {
          isGoing:true,
          numberOfGuests:2
        };

        this.handleInputChange = this.handleInputChange.bind(this);
      }

      handleInputChange(event){
        const target = event.target;
        const value = target.type === "checkbox" ? target.checked : target.value;
        const name = target.name;

        // [name] is ES6 computed property name syntax
        // same to 
        // var partialState = {};
        // partialState[name] = value;
        // this.setState(partialState);
        
        this.setState({
          [name]:value
        })
      }

      render(){
        return (
          <form>
            <label>
              Is going:
              <input name="isGoing" type="checkbox" checked={this.state.isGoing} onChange={this.handleInputChange}/>
            </label>
            <br/>
            <label>
              Number of guests:
              <input name="numberOfGuests" type="number" value={this.state.numberOfGuests} onChange={this.handleInputChange}/>
            </label>
          </form>
        );
      }
    }


    ReactDOM.render(<Reservation/>,document.getElementById('root'));
  </script>
  <!--
      Note: this page is a great way to try React but it's not suitable for production.
      It slowly compiles JSX with Babel in the browser and uses a large development build of React.

      To set up a production-ready React build environment, follow these instructions:
      * https://reactjs.org/docs/add-react-to-a-new-app.html
      * https://reactjs.org/docs/add-react-to-an-existing-app.html

      You can also use React without JSX, in which case you can remove Babel:
      * https://reactjs.org/docs/react-without-jsx.html
      * https://reactjs.org/docs/cdn-links.html
    -->
</body>

</html>